import { defineStore } from 'pinia'
import { ref } from 'vue'
import { getPreferredLanguage } from '../utils/i18n'

export const useLanguageStore = defineStore('language', () => {
  const currentLanguage = ref(localStorage.getItem('locale') || getPreferredLanguage())

  function setLanguage(lang: string) {
    currentLanguage.value = lang
    localStorage.setItem('locale', lang)
  }

  return {
    currentLanguage,
    setLanguage
  }
})